package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.StandardReqDTO;
 import com.iafme.dto.res.StandardResDTO;
 import com.iafme.model.Standard;
import com.iafme.model.StandardMapper;
import com.iafme.service.StandardService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/21 20:51
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class StandardServiceImpl extends ServiceImpl<StandardMapper, Standard> implements StandardService {

    @Override
    public Page<StandardResDTO> lists(StandardReqDTO standardReqDTO) {
        Page<Standard> page=new Page<>(standardReqDTO.getPageNum(), standardReqDTO.getPageSize());
        LambdaQueryWrapper<Standard> eq = Wrappers.lambdaQuery(Standard.class)
                .eq(StrUtil.isNotEmpty(standardReqDTO.getName()), Standard::getName, standardReqDTO.getName())
                .orderByDesc(Standard::getCreateTime);
        return Convert.convert(new TypeReference<Page<StandardResDTO>>() {
        },this.page(page, eq));
    }
}
